//
//  ActivityDetailsView.m
//  豆瓣
//
//  Created by lanou3g on 15/12/11.
//  Copyright © 2015年 HaiTeng. All rights reserved.
//

#import "ActivityDetailsView.h"
#import "UIImageView+WebCache.h"
@interface ActivityDetailsView ()

@property(nonatomic,strong)UIImageView *time_image_; //时间标题图片
@property(nonatomic,strong)UIImageView *address_image_; //地址标题图片
@property(nonatomic,strong)UIImageView *category_image_; //类型标题图片
@property(nonatomic,strong)UIImageView *name_image_; //活动举办标题方图片

@property(nonatomic,strong)UILabel *time_label_; //时间标题
@property(nonatomic,strong)UILabel *category_name_label_; //活动类型标题
@property(nonatomic,strong)UILabel *wisher_label_;//兴趣标题
@property(nonatomic,strong)UILabel *participant_label_;//参加标题








@end


@implementation ActivityDetailsView

- (instancetype)initWithFrame:(CGRect)frame{
    
    self = [super initWithFrame:frame];
    if (self) {
        [self addAllViews];
    }
    
    return self;
    
}




- (void)setModel_activity_:(ActivityModel *)model_activity_
{
    
    if (model_activity_) {
        
        self.title_.text = model_activity_.title;
        
        NSString *begin = [model_activity_.begin_time substringFromIndex:5];
        self.begin_time_.text = [begin substringToIndex:11];
        
        NSString *end = [model_activity_.end_time substringFromIndex:5];
        self.end_time_.text = [end substringToIndex:11];
        
        self.name_.text = model_activity_.name;
        self.address_.text = model_activity_.address;
        self.category_name_.text = model_activity_.category_name;
        self.participant_count_.text = [NSString stringWithFormat:@"%d人",model_activity_.participant_count];
        self.wisher_count_.text = [NSString stringWithFormat:@"%d人",model_activity_.wisher_count];
        [self.image_ sd_setImageWithURL:[NSURL URLWithString:model_activity_.image]];
        self.content_.text = model_activity_.content;
        
        
    }
    
    
}






- (void)addAllViews{

    
    
    self.scrollView = [[UIScrollView alloc] init];
    [self addSubview:self.scrollView];
    
    
    
    //活动标题
    self.title_ = [[UILabel alloc] init];

      self.title_.numberOfLines = 0;
    [self.scrollView addSubview:self.title_];
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    //时间标题图片
    self.time_image_ = [[UIImageView alloc] init];
    self.time_image_.image = [UIImage imageNamed:@"icon_catalog_blue"];
    [self.scrollView addSubview:self.time_image_];
    
    
    
    //   begin_time_cell; //开始时间
    
    self.begin_time_ = [[UILabel alloc] init];
//    self.begin_time_.text = @"10-19 20:28";
    self.begin_time_.font = [UIFont systemFontOfSize:13];
    [self.scrollView addSubview:self.begin_time_];
    
    
    
    
    
    //time_label; //时间标题
    
    self.time_label_ = [[UILabel alloc] init];
    self.time_label_.text = @"--";
    [self.scrollView addSubview:self.time_label_];
    
    // end_time_cell; //结束时间
    self.end_time_ = [[UILabel alloc] init];
//    self.end_time_.text = @"10-19 20:28";
    self.end_time_.font = [UIFont systemFontOfSize:13];
    [self.scrollView addSubview:self.end_time_];
    
    //    address_image; //地址标题图片
    self.address_image_ = [[UIImageView alloc] init];
    self.address_image_.image = [UIImage imageNamed:@"icon_spot_blue"];
    [self.scrollView addSubview:self.address_image_];
    
    
    //   address_cell; //地址
    self.address_ = [[UILabel alloc] init];
//    self.address_.text = @"背景决定就是了空间的时间考";
    self.address_.font = [UIFont systemFontOfSize:13];
    self.address_.numberOfLines = 0;
   
    
    [self.scrollView addSubview:self.address_];
    
    
//    name_image_; //活动举办标题方图片
    self.name_image_ = [[UIImageView alloc] init];
    self.name_image_.image = [UIImage imageNamed:@"icon_sponsor_blue"];
    [self.scrollView addSubview:self.name_image_];
    
    
    //活动举办方name_
    self.name_ = [[UILabel alloc] init];
//    self.name_.text = @"手机点击撒";
    self.name_.font = [UIFont systemFontOfSize:13];
    [self.scrollView addSubview:self.name_];
    
    
    
    
    
    //    category_image; //类型标题图片
    self.category_image_ = [[UIImageView alloc] init];
    self.category_image_.image = [UIImage imageNamed:@"icon_catalog_blue"];
    [self.scrollView addSubview:self.category_image_];
    
    
    
    
    //category_name_label; //活动类型标题
    self.category_name_label_ = [[UILabel alloc] init];
    self.category_name_label_.text = @"类型:";
    self.category_name_label_.font = [UIFont systemFontOfSize:13];
    [self.scrollView addSubview:self.category_name_label_];
    
    //category_name_cell; //活动类型
    self.category_name_ = [[UILabel alloc] init];
//    self.category_name_.text = @"展览展览";
    self.category_name_.font = [UIFont systemFontOfSize:13];
    [self.scrollView addSubview:self.category_name_];
    
    //    wisher_label;//兴趣标题
    self.wisher_label_ = [[UILabel alloc] init];
    self.wisher_label_.text = @"感兴趣:";
    self.wisher_label_.font = [UIFont systemFontOfSize:13];
    [self.scrollView addSubview:self.wisher_label_];
    
    
    //wisher_count_cell; //感兴趣人数
    self.wisher_count_ = [[UILabel alloc] init];
//    self.wisher_count_.text = @"4444";
    self.wisher_count_.textColor = [UIColor redColor];
    self.wisher_count_.font = [UIFont systemFontOfSize:13];
    [self.scrollView addSubview:self.wisher_count_];
    
    
    
    
    
    //    participant_label;//参加标题
    self.participant_label_ = [[UILabel alloc] init];
    self.participant_label_.text = @"参加:";
    self.participant_label_.font = [UIFont systemFontOfSize:13];
    [self.scrollView addSubview:self.participant_label_];
    
    
    //participant_count_cell; //参加人数
    self.participant_count_ = [[UILabel alloc] init];
//    self.participant_count_.text = @"5555";
    self.participant_count_.textColor = [UIColor redColor];
    self.participant_count_.font = [UIFont systemFontOfSize:13];
    [self.scrollView addSubview:self.participant_count_];

    
    
    //image_cell;  //活动图像(先显示占位图像)
    self.image_= [[UIImageView alloc] init];
    self.image_.image = [UIImage imageNamed:@"picholder"];
    [self.scrollView addSubview:self.image_];
    
    
    
    
    //活动介绍
    self.sayYesLableHAHAHA = [[UILabel alloc] init];
   self.sayYesLableHAHAHA.font = [UIFont systemFontOfSize:20];
    self.sayYesLableHAHAHA.text = @"活动介绍";
    [self.scrollView addSubview:self.sayYesLableHAHAHA];
    
    
    
    //活动详情
    self.content_ = [[UILabel alloc] init];
//    self.content_.backgroundColor = [UIColor redColor];
 
     [self.scrollView addSubview:self.content_];
    
    
}



- (void)layoutSubviews
{
    [super layoutSubviews];
    
    
    self.scrollView.frame = [UIScreen mainScreen].bounds;
//    self.scrollView.contentSize = CGSizeMake(self.frame.size.width, self.frame.size.height * 2 + 100);
    self.scrollView.scrollEnabled = YES;
    self.scrollView.showsVerticalScrollIndicator = NO;
    
    
    
    
    //活动标题
    self.title_.frame = CGRectMake(15, 0, self.frame.size.width - 30, 50);
    
    
    
    
    
    
    
    
    
    
    
    
    //image_cell;  //活动图像(先显示占位图像)
    
   
    self.image_.frame = CGRectMake(15, CGRectGetMaxY(self.title_.frame), self.frame.size.width / 3 - 20, self.frame.size.height / 3 - 20);
    
    
    
    
    //时间标题图片
    self.time_image_.frame = CGRectMake(self.frame.size.width / 3, CGRectGetMaxY(self.title_.frame), 16, 16);
    
    //   begin_time_cell; //开始时间
    self.begin_time_.frame = CGRectMake(CGRectGetMaxX(self.time_image_.frame) + 5, self.time_image_.frame.origin.y, 80, 16);
    
    
    //time_label; //时间标题
    self.time_label_.frame = CGRectMake(CGRectGetMaxX(self.begin_time_.frame), self.self.begin_time_.frame.origin.y, 18, 16);
    
    
    // end_time_cell; //结束时间
    self.end_time_.frame = CGRectMake(CGRectGetMaxX(self.time_label_.frame), self.time_label_.frame.origin.y, 80, 16);
    
    //    name_image_; //活动举办标题方图片
 
    self.name_image_.frame = CGRectMake(self.time_image_.frame.origin.x, CGRectGetMaxY(self.time_image_.frame) + 6, self.time_image_.frame.size.width, self.time_image_.frame.size.height);
    
     //活动举办方name_
    self.name_.frame = CGRectMake(self.begin_time_.frame.origin.x, self.name_image_.frame.origin.y, 180, 16);
    
    
    
    //    category_image; //类型标题图片
    self.category_image_.frame = CGRectMake(self.name_image_.frame.origin.x, CGRectGetMaxY(self.name_image_.frame) + 6, self.name_image_.frame.size.width, self.name_image_.frame.size.height);
    
    
    //category_name_cell; //活动类型标题
    self.category_name_label_.frame = CGRectMake(CGRectGetMaxX(self.category_image_.frame), self.category_image_.frame.origin.y, 30, self.category_image_.frame.size.height);
    
    //category_name_cell; //活动类型
    self.category_name_.frame = CGRectMake(CGRectGetMaxX(self.category_name_label_.frame) + 10, self.category_name_label_.frame.origin.y, 60, self.category_name_label_.frame.size.height);
    
    
    
    
    //    address_image; //地址标题图片
    self.address_image_.frame = CGRectMake(self.category_image_.frame.origin.x, CGRectGetMaxY(self.category_image_.frame) + 6, self.category_image_.frame.size.width,  self.category_image_.frame.size.height);
    
    
    
    //   address_cell; //地址
    self.address_.frame = CGRectMake(CGRectGetMaxX(self.address_image_.frame), self.address_image_.frame.origin.y, 168, self.address_image_.frame.size.height * 2);
    
    //兴趣标题
    self.wisher_label_.frame = CGRectMake(self.address_image_.frame.origin.x, CGRectGetMaxY(self.address_.frame) + 5, 50, 30);
   //感兴趣人数
    self.wisher_count_.frame = CGRectMake(CGRectGetMaxX(self.wisher_label_.frame), self.wisher_label_.frame.origin.y, 200, 30);
    
    
    //参加标题
    self.participant_label_.frame = CGRectMake(self.wisher_label_.frame.origin.x, CGRectGetMaxY(self.wisher_label_.frame), self.wisher_label_.frame.size.width, self.wisher_label_.frame.size.height);
    
    //参加人数
    self.participant_count_.frame = CGRectMake(self.wisher_count_.frame.origin.x, self.participant_label_.frame.origin.y, self.wisher_count_.frame.size.width, self.wisher_count_.frame.size.height);
    

    //活动介绍
    self.sayYesLableHAHAHA.frame = CGRectMake(15, CGRectGetMaxY(self.image_.frame),self.frame.size.width - 30, 30);
    

    
    //活动详情
 
//    self.content_.frame = CGRectMake(15, CGRectGetMaxY(self.sayYesLableHAHAHA.frame), self.frame.size.width - 30, 980);
    self.content_.numberOfLines = 0;
//    self.content_.baselineAdjustment = UIBaselineAdjustmentNone;
//    self.content_.minimumScaleFactor = 0.5;
    self.content_.font = [UIFont systemFontOfSize:13];
   
    
    
    CGFloat heiht = [self geviHeight:self.content_.text];
    self.scrollView.contentSize = CGSizeMake(self.frame.size.width, heiht + self.frame.size.height / 2 + 42);
    
    
    self.content_.frame = CGRectMake(15, CGRectGetMaxY(self.sayYesLableHAHAHA.frame), self.frame.size.width - 30,heiht + 42);
    
    
}


- (CGFloat)geviHeight:(NSString *)str
{
    CGRect rect = [str boundingRectWithSize:CGSizeMake(self.frame.size.width - 30, 100000) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName : [UIFont systemFontOfSize:13]} context:nil];
    
    return rect.size.height;
}



@end
